from pymysql import Connection as cc

con = None

try:
    con = cc(
        host='159.138.150.44',
        port=3306,
        user='root',
        password='lgifLZKX86EcInQw',
        database='tianhao',
        autocommit=True
    )
    # 创建游标
    cursors = con.cursor()
    """
    
    1. 向表中添加字段：
    ALTER TABLE Stu ADD COLUMN age INT;
    2. 删除表中的字段：
    ALTER TABLE stu DROP COLUMN age;
    3. 修改字段的名字：
    ALTER TABLE Stu CHANGE COLUMN Sname S2name VARCHAR(20);
    4. 修改字段的类型：
    ALTER TABLE Stu MODIFY id VARCHAR(20);
    5. 修改表的名字：
    ALTER TABLE Stu4 RENAME TO Stu5;
    """
    sql1 = """
    ALTER TABLE business_msg2 ADD COLUMN msg_addree varchar(64);
"""
    sql2 = """
    ALTER TABLE business_msg2 DROP COLUMN msg_addree;
"""
    sql3 = """
    ALTER TABLE business_msg2 ADD COLUMN msg_addree varchar(64);

"""
    sql4 = """
    ALTER TABLE business_msg2 CHANGE COLUMN Sname S2name VARCHAR(20);
"""
    sql5 = """
    ALTER TABLE business_msg2 MODIFY id VARCHAR(20);

"""
    sql6 = """
    ALTER TABLE business_msg2 RENAME TO business_msg3;

"""
    #利用游标执行sql语句
    cursors.execute(sql1)

except Exception as e:
    print('异常:', e)
finally:
    if con:
        con.close()
